home *** CD-ROM | disk | FTP | other *** search
Wrap
// HQPreferencesController.m // // You may freely copy, distribute, and reuse the code in this example. // Apple disclaims any warranty of any kind, expressed or implied, as to its // fitness for any particular use. #import "HQPreferencesController.h" #ifdef ENABLE_PREFERENCES NSString *HQPreferencesDidChangeNotification = @"HQPreferencesDidChange"; @implementation HQPreferencesController + (id)sharedPreferencesController { static HQPreferencesController *sharedInstance = nil; if (!sharedInstance) { sharedInstance = [[HQPreferencesController alloc] init]; } return sharedInstance; } - (id)init { self = [super initWithWindowNibName:@"HQPreferences" owner:self]; if (self) { [self setWindowFrameAutosaveName:@"HQPreferences"]; [self readDefaults]; } return self; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } - (void)readDefaults { // FILL THIS IN: Read from user defaults if you cache values } - (void)revertPanel { // FILL THIS IN: Update the preferences UI to reflect the current pref settings. } - (void)windowDidLoad { [super windowDidLoad]; [self revertPanel]; } - (void)didChange { // CALL THIS: Call this method any time the value of a preference is changed from the panel in addition to actually setting the value in NSUserDefaults and in any local cache. [[NSNotificationCenter defaultCenter] postNotificationName:HQPreferencesDidChangeNotification object:self]; } - (void)windowWillClose:(NSNotification *)aNotification { // Try and make sure to catch edits when the user closes the window. [[self window] makeFirstResponder:[self window]]; } - (void)windowDidResignKey:(NSNotification *)aNotification { // Try and make sure to catch edits when the user activates another window. [[self window] makeFirstResponder:[self window]]; } @end #endif